/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __PICTUREFORMAT_DECOMPRESSORJPEG_H__
#define __PICTUREFORMAT_DECOMPRESSORJPEG_H__

#include "Decompressor.h"
#include <NoCopy.h>
#include <Gluck.h>
#include "jpeglib/jpeglib.h"
#include <ColorPacked.h>

namespace liba
{
namespace pictureformat
{

struct customJpegManager;

/** @warning only uncompressed 24- and 32-bit Windows Bitmaps are supported. */
class DecompressorJpeg : public Decompressor, private Nocopy
{
	unsigned int jpeg_width;
	unsigned int jpeg_height;

	ColorPacked * decoded_data;
	Format desired_format;
	int scan_line;
public:
	DecompressorJpeg(const void * data, int size);
	virtual ~DecompressorJpeg();
	virtual int get_width(int frame)const
	{
		return jpeg_width;
	}
	virtual int get_height(int frame)const
	{
		return jpeg_height;
	}
	virtual Format get_best_format()const
	{
		return pictureformat::R8G8B8;
	}
	virtual int get_frame_count()const
	{
		return 1;
	}
	virtual void reset(Format f, int frame)
	{
		if( frame > 0 )
			THROW(Gluck( __FUNCTION__, "Frame is out of range" ));
		desired_format = f;

		scan_line = 0;
	}
	virtual void unpack_scanline(void * dst);
	virtual void skip_scanline(int count);
};

} // namespace pictureformat
} // namespace liba
using namespace liba;

#endif //__PICTUREFORMAT_DECOMPRESSORJPEG_H__